package com.competition.reception.service.impl;

import com.competition.commonutils.R;
import com.competition.reception.entity.User;
import com.competition.reception.entity.vo.UserInfo;
import com.competition.reception.entity.vo.UserQueryVo;
import com.competition.reception.mapper.UserMapper;
import com.competition.reception.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.competition.servicebase.exceptionhandler.MyException;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-03
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public R getUserByCondition(UserQueryVo userQueryVo) {
        List<UserInfo> userInfoList=baseMapper.listByCondition(userQueryVo);
        int usercount=baseMapper.getUserCount(userQueryVo);
        return R.ok().data("usercount",usercount).data("userInfoList",userInfoList);
    }

    @Override
    public Integer userBlackListManage(String id) {
        User user = baseMapper.selectById(id);
        if(user.getIsDisabled()==1){
            user.setIsDisabled(0);
        } else {
            user.setIsDisabled(1);
        }
        int i = baseMapper.updateById(user);
        if(i!=1) throw new MyException(201,"操作失败");
        return user.getIsDisabled();
    }

}
